//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    name:app.globalData.nickName,
    icon:app.globalData.avatarUrl,
    account:'',
    pwd:'',
    pwdvisible:false,
    hidden:true,
    title:'',
    Loading:false
  },
  onLoad: function (options) {
    var account =options.account;
    this.setData({
      account:account,
    })
  },
  confirm(){
    this.setData({
      hidden:true
    })
  },
  lookpwd(){
    this.setData({
      pwdvisible:!this.data.pwdvisible
    })
  },
  pwdtinput(e){
    this.setData({
      pwd:e.detail.value
    })
  },
  login (){
    let self = this;
    if(self.data.pwd==0){
      self.setData({
        title:"请输入密码",
        hidden:false
      })
      return;
    }
    self.setData({Loading:true})
    getApp().request({
      url:'login',
      data:{
        mobile:self.data.account,
        psw: self.data.pwd
      },success:function(res) {
        if(res.data.flag){
          wx.setStorageSync('localaccount', self.data.account)
          wx.setStorageSync('localpsw', self.data.pwd)
          getApp().globalData.UserData = res.data.data;
          self.setData({Loading:false})
          self.loginsuc();
        }
        else{
          self.setData({
            title:res.data.msg,
            hidden:false,
            Loading:false
          })
        }
      },fail(){
        wx.showModal({
            content: '请求失败',
            showCancel:false,
            success: function(res) {
            }
        })
      }
    },true)
  },
  loginsuc(){
    wx.reLaunch({
      url: '../realtime/realtime',
      success: function(res){
        // success
      }
    })
  }
})
